package com.sas.common.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = false)
public class GenderConverter implements AttributeConverter<Integer, String> {

    @Override
    public String convertToDatabaseColumn(Integer attribute) {
        if (attribute == null) return null;
        switch (attribute) {
            case 1:
                return "MALE";
            case 2:
                return "FEMALE";
            case 3:
                return "OTHER";
            default:
                return null;
        }
    }

    @Override
    public Integer convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        switch (dbData) {
            case "MALE":
                return 1;
            case "FEMALE":
                return 2;
            case "OTHER":
                return 3;
            default:
                return null;
        }
    }
}